package server;

import both.Game;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import both.Question;
import both.StringFormatter;

public class ServerAnswerTab extends JPanel implements ActionListener{
    private int width = (int)Game.width - 250;

    
    public ServerAnswerTab(GameShowServer server) {
        Question question = server.getGame().getCurrentQuestion();
        setLayout(new GridLayout(0,1,10,30));
        setAlignmentX(JPanel.LEFT_ALIGNMENT);
        setBorder(BorderFactory.createEmptyBorder(30,30,30,30));
        displayQuestion(question);
        setName("server-answer-tab");
    }

    

    public void displayQuestion(Question question){

        JPanel panel1 = new JPanel();
        JLabel questionText = new JLabel(StringFormatter.formatString(question.getQuestionText(), StringFormatter.QUESTION_STR, width));
        panel1.add(questionText);
        add(panel1);

        

        JPanel panel2 = new JPanel();
        JLabel answerText = new JLabel(StringFormatter.formatString(question.getAnswerChoices().get(question.getCorrectAnswer()), StringFormatter.ANSWER_STR, width));
        panel2.add(answerText);
        add(panel2);

        

        JPanel panel3 = new JPanel();
        JLabel explain = new JLabel(StringFormatter.formatString(question.getExplanation(), StringFormatter.ANSWER_STR, width));
        panel3.add(explain);
        add(panel3);

        

        JPanel panel4 = new JPanel();
        panel4.setAlignmentX(JPanel.CENTER_ALIGNMENT);
        JButton cont = new JButton(StringFormatter.formatString("Continue", StringFormatter.QUESTION_STR));
        cont.addActionListener(this);
        cont.setActionCommand("CONTINUE");
        panel4.add(cont);
        add(panel4);

    }

    

    public void actionPerformed(ActionEvent event) {
        String name = event.getActionCommand();
        if(name.equals("CONTINUE")){
            Server.changeGameTab();
        }

    }
}
